class ODRender {
  constructor(map) {
    this.map = map;
  }
  hexToRGB(hex) {
    // 去除 # 符号（如果有）
    hex = hex.replace('#', '');

    // 将十六进制颜色码转换为 RGB 值
    const r = Number.parseInt(hex.slice(0, 2), 16);
    const g = Number.parseInt(hex.slice(2, 4), 16);
    const b = Number.parseInt(hex.slice(4, 6), 16);

    // 返回颜色数组
    return [r, g, b];
  }
  ODRenderEntry(options) {
    const { isFieldBasedRender, layout, mapLayer, paint, paintBasedField } =
      options;
    // if (this.map.getLayer(sourceLayer + '_cluster') !== undefined) {
    //   return {
    //     status: 'error',
    //     message: '已存在该点图层的聚合图层，暂不支持对同一点图层添加多个聚合图层！'
    //   }
    // }
    mapLayer.props.getHeight = layout.height / 5;
    mapLayer.props.getSourcePosition = layout['source-position'];
    mapLayer.props.greatCircle = layout['is-great-circle'];
    // mapLayer.organizationType = 'singleLayer'
    // mapLayer.layout = {
    //   'visibility': 'visible'
    // }
    // 如果依据字段渲染
    if (isFieldBasedRender) {
      mapLayer.props.getSourceColor = paintBasedField['source-color'];
      mapLayer.props.getTargetColor = paintBasedField['target-color'];
      mapLayer.props.getWidth = paintBasedField['line-width'];
    } else {
      mapLayer.props.getSourceColor = this.hexToRGB(paint['source-color']);
      mapLayer.props.getTargetColor = this.hexToRGB(paint['target-color']);
      mapLayer.props.getWidth = paint['line-width'];
    }
    mapLayer.props.getTargetPosition = (d) => d.geometry.coordinates;
    const ODLayer = mapLayer;
    return {
      status: 'success',
      message: '成功',
      data: ODLayer,
    };
  }
}
export default ODRender;
